package com.meishij.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jash.myutils.utils.ImageUtils;
import com.meishij.R;
import com.meishij.entry.MallSellEntry;

import java.util.List;

/**
 * Created by 肖荣 on 2016/10/14.
 */

public class MallItemDetailRecyclerAdapter extends RecyclerView.Adapter<MallItemDetailRecyclerAdapter.ViewHolder> {
    private Context context;
    private List<MallSellEntry.ObjBean.DetailBean> list;

    public MallItemDetailRecyclerAdapter(Context context, List<MallSellEntry.ObjBean.DetailBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_mall_sell_item_detail_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if(list.get(position).getType()==1){//加载图片
            ImageUtils.loadImage(holder.mall_sell_item_detail_image,list.get(position).getImage().getSmall(),R.mipmap.box_def_icon);
            holder.mall_sell_item_detail_text.setVisibility(View.GONE);
        }else{//加载文字
            holder.mall_sell_item_detail_text.setText(list.get(position).getContent());
            holder.mall_sell_item_detail_image.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private TextView mall_sell_item_detail_text;
        private ImageView mall_sell_item_detail_image;

        public ViewHolder(View itemView) {
            super(itemView);
            mall_sell_item_detail_text = ((TextView) itemView.findViewById(R.id.mall_sell_item_detail_text));
            mall_sell_item_detail_image = ((ImageView) itemView.findViewById(R.id.mall_sell_item_detail_image));
        }
    }
}
